/**
 * ReportGear(2011)
 */
package com.reportgear.report.model.calculator;

import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import com.reportgear.core.data.SalaryHelper;
import com.reportgear.core.data.model.SalaryDataObject;
import com.reportgear.report.model.ReportModel;
import com.reportgear.report.model.cell.Cell;
import com.reportgear.report.model.cell.value.CrossDocDataObject;

/**
 * 
 * 交叉数据薪酬档案对象值计算
 * 
 * @version 1.0 2011-4-10
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since Report 1.0
 */
public class CrossDocDataObjectValueCalculator extends AbstractCalculator {
	public CrossDocDataObjectValueCalculator() {

	}

	@Override
	public ReportModel calculate(ReportModel model, CalcParameter parameter) {
		if (logger.isDebugEnabled()) {
			logger.debug("计算模型：薪酬档案值计算");
		}

		ReportModel calcModel = model;

		// 与上一个计算模型重复
		Set<Integer> colSet = new HashSet<Integer>();
		colSet.add(-1);

		List<SalaryDataObject> dataList = SalaryHelper.INSTANCE.getPayDoc(parameter.getPaymentId(), parameter
				.getSalaryObjectType(), parameter.getMaxLevel(), parameter.getSelectObjSet(), colSet);

		Iterator<Cell> cells = calcModel.getCellsIteratorByCellElementClass(CrossDocDataObject.class);
		for (Iterator<Cell> i = cells; i.hasNext();) {
			Cell cell = i.next();

			CrossDocDataObject value = (CrossDocDataObject) cell.getValue();

			for (SalaryDataObject sdo : dataList) {
				if (sdo.getInt("objectID") == value.getyId()) {
					value.addValue(sdo);
					break;
				}
			}
		}

		return calcModel;
	}
}
